class Register{
    constructor(container){
        this.container=container;
        this.creatDOM().then($.proxy(this.init,this));
    }
    creatDOM(){
        return new Promise(resolve=>{
            this.container.load("/html/component/common/register.html",resolve);
        }
        );
    }
    init(){
    this.userInput = $("#registerUserInput");
    this.pwdInput = $("#registerPwdInput");
    this.confimInput = $("#confirm");
    this.btn = $("#register-btn");
    this.succ = $("#register-succ");
    this.fail = $("#register-fail");
    this.closeBtn = $("#register-close");

    this.bindEvents();
    }
    bindEvents(){
        this.btn.on("click",$.proxy(this.handleBtnClick,this));
        // this.btn.on("click",this.handleBtnClick.bind(this));
    }
    handleBtnClick(){
        let username = this.userInput.val();
        let password = this.pwdInput.val();
        let confimPwd = this.confimInput.val();
        //----------表单验证----------------
        //发送ajax请求
        // $.post("http://rap2api.taobao.org/app/mock/161780/register", {username, password}, $.proxy(this.handleRegisterSucc, this));
        $.post(baseUrl + "/user/register",{username,password},this.handleRegisterSucc.bind(this));
    }
    handleRegisterSucc(res){
        //注册成功
        if(res.res_code==1){
            this.succ.removeClass("hide");
            setTimeout(()=>{
                this.succ.addClass("hide");
                this.closeBtn.trigger(new $.Event("click"));
            },1800)
        }else{
            this.fail.removeClass("hide");
            setTimeout(()=>{
                this.fail.addClass("hide");
            },1800)
        }
    }
}